From 8e65dd3ea5f8b923d598fd114a0d1870cb7e7daa Mon Sep 17 00:00:00 2001 From: Keir Fraser Date: Fri, 5 Dec 2008 14:46:38 +0000 Subject: [PATCH] x86, time: Fix scale_reciprocal(). Signed-off-by: Keir Fraser --- xen/arch/x86/time.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/xen/arch/x86/time.c b/xen/arch/x86/time.c index c4dc8f4ae0..759223b062 100644 --- a/xen/arch/x86/time.c +++ b/xen/arch/x86/time.c @@ -152,14 +152,23 @@ static inline u64 scale_delta(u64 delta, struct time_scale *scale) /* Compute the reciprocal of the given time_scale. */ static inline struct time_scale scale_reciprocal(struct time_scale scale) { - u32 q, r; + struct time_scale reciprocal; + u32 dividend; + + dividend = 0x80000000u; + reciprocal.shift = 1 - scale.shift; + while ( unlikely(dividend >= scale.mul_frac) ) + { + dividend >>= 1; + reciprocal.shift++; + } asm ( "divl %4" - : "=a" (q), "=d" (r) - : "0" (1), "1" (0), "r" (scale.mul_frac) ); + : "=a" (reciprocal.mul_frac), "=d" (dividend) + : "0" (0), "1" (dividend), "r" (scale.mul_frac) ); - return (struct time_scale) { .shift = -scale.shift, .mul_frac = q }; + return reciprocal; } /* -- 2.30.2